﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;
using TjZheng.Framework;
using TjZheng.Controls;

namespace TjZheng.EasyUI
{
    public class EasyUIQueryControl : QueryInfo, IBaseControl
    {
        /// <summary>
        /// 控件ID
        /// </summary>
        public string Id { get; set; }
        /// <summary>
        /// 查询标题
        /// </summary>
        public string QueryTitle { get; set; }
        /// <summary>
        /// EasyUI样式名
        /// </summary>
        public string EasyUIClass { get; set; }
        /// <summary>
        /// Html属性
        /// </summary>
        public IDictionary<string, object> HtmlAttributes { get; set; }
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="QueryField">查询字段QueryField必输</param>
        public EasyUIQueryControl(string QueryField)
            : this(string.Empty, QueryField)
        {

        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="Prefix">Model前缀必输</param>
        /// <param name="QueryField">查询字段QueryField必输</param>
        public EasyUIQueryControl(string Prefix, string QueryField)
            : base(Prefix)
        {
            if (QueryField.IsNull())
            {
                throw new ArgumentException("查询字段QueryField不能为空");
            }
            this.QueryField = QueryField;
        }

        public override string ToString()
        {
            StringBuilder objStringBuilder = new StringBuilder();
            objStringBuilder.Append(RenderHtml());
            objStringBuilder.Append(QueryToHtml());
            return objStringBuilder.ToString();
        }

        public override string QueryToHtml()
        {
            StringBuilder objStringBuilder = new StringBuilder();
            objStringBuilder.Append(QueryInputHidden("QueryInfo", "Prefixs", this.Prefix));
            objStringBuilder.Append(QueryInputHidden(this.Prefix, "QueryField", this.QueryField));
            objStringBuilder.Append(QueryInputHidden(this.Prefix, "QueryDataType", this.QueryDataType.ToString()));
            objStringBuilder.Append(QueryInputHidden(this.Prefix, "QueryMethod", this.QueryMethod.ToString()));
            return objStringBuilder.ToString();
        }

        public virtual string RenderHtml()
        {
            return string.Empty;
        }
    }
}
